# 1. 注释
# 这是单行注释
"""
这是多行注释
"""

# 2. 变量与数据类型
name = "Alice"  # 字符串
age = 25  # 整数
height = 1.68  # 浮点数
is_student = True  # 布尔值
hobbies = ["读书", "编程", "音乐"]  # 列表
info = {"city": "北京", "score": 90}  # 字典

# 3. 打印输出
print(f"{name} 今年 {age} 岁，身高 {height} 米")

# 4. 条件判断
if age >= 18:
    print("成年")
else:
    print("未成年")

# 5. 循环
# for 循环
for hobby in hobbies:
    print("爱好:", hobby)

# while 循环
count = 0
while count < 3:
    print("计数:", count)
    count += 1


# 6. 函数
def greet(person):
    return f"你好，{person}！"


print(greet(name))


# 7. 类与对象
class Student:
    def __init__(self, name, age):
        self.name = name
        self.age = age

    def introduce(self):
        print(f"我是 {self.name}，今年 {self.age} 岁")


student1 = Student("小明", 20)
student1.introduce()

# 8. 异常处理
try:
    x = 1 / 0
except ZeroDivisionError:
    print("除数不能为 0")
finally:
    print("结束计算")

# 9. 文件操作
with open("demo.txt", "w", encoding="utf-8") as f:
    f.write("这是一个写入文件的示例\n")

# 10. 模块导入
import math

print("π的值为:", math.pi)

if __name__ == "__main__":
    print("main.py")
